<!--
 * @Description: Web project
 * @Version: 2.0
 * @Autor: WenChing
 * @Email: 2510129345@qq.com
 * @Date: 2020-08-11 16:14:48
 * @LastEditors: WenChing
 * @LastEditTime: 2020-08-11 16:48:36
-->
<template>
  <div>
    <van-field
      v-model="text"
      :label="label"
      :type="type"
      :placeholder="placeholder"
      :rule="rule"
    />
  </div>
</template>

<script>
export default {
  props:['label','type','placeholder','rule'],
  data() {
    return {
      text:''
    };
  },
  watch:{
    // 可以检测输入框内容发送改变触发动作
    text(){
      // console.log('aaa');
      // 检测正则
      this.handlerule()
    }
  },
  created() {},
  mounted() {},
  methods: {
    handlerule(){
     const rue = new RegExp(this.rule)
    //  console.log(rue);
    //  判断正则满足，发送请求
    if(rue.test(this.text)){
      // 传递给父组件  
    this.$emit('inputChange',this.text)
    }
    }
  }
};
</script>

<style scoped lang="less">
</style>
